package model;

import dao.MealDAO;

public class Meal {
        
        private String name;
        private String description;
        private String img_url;
        private int price;
        private String title;
        private String type;
        private int active;
        
        private MealDAO mealDAO;
        
        public Meal() {
        	mealDAO = new MealDAO();
        }
        
        public String getName() {return name;}  
        public String getDescription() {return description;}
        public String getImg_url() {return img_url;}
        public int getPrice() {return price;}
        public String getTitle() {return title;}
        public String getType() {return type;}
        public int getActive() {return active;}

        public void setName(String name) {this.name = name;}
        public void setDescription(String description) {this.description = description;}
        public void setImg_url(String img_url) {this.img_url = img_url;}
        public void setPrice(int price) {this.price = price;}
        public void setTitle(String title) {this.title = title;}
        public void setType(String type) {this.type = type;}
        public void setActive(int s) {this.active = s; }
        
        public boolean register(String name, String description, String img_url, int price, String title, String type) {
        	
        	Meal m = new Meal();
        	m.setName(name);
        	m.setDescription(description);
        	m.setImg_url(img_url);
        	m.setPrice(price);
        	m.setTitle(title);
        	m.setType(type);
        	m.setActive(1);
        	
        	mealDAO.create(m);
        	
        	return true;        	
        }        
        
        public boolean modify( String name, String description, String img_url, int price, String title, String type) {
        	Meal m0 = mealDAO.select (name);
        	
        	if (m0 != null ){
        		Meal m = new Meal();
        		m.setName(name);
            	m.setDescription(description);
            	m.setImg_url(img_url);
            	m.setPrice(price);
            	m.setTitle(title);
            	m.setType(type);
            	m.setActive(1);
            	
            	mealDAO.update(m);
            	
            	return true;
        	}
        	
        	return false;
        }
        	
        public boolean delete(String name) {
        	Meal m = mealDAO.select(name);
        	if ( m != null ) {
        		m.setActive(0);
        		mealDAO.update(m);
        		return true;
        	}
        	return false;
        }
        
        
}
